﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace The_Wumpers
{

    public partial class Form1 : Form
    {
        public Trivia trivia;
        TriviaStruct ts;
        int score;
        int numberofquestions;
        public bool correct= false;

        public Form1()
        {
            InitializeComponent();
            trivia = new Trivia();
          

			this.Load += OnLoad; //retrieves the question when program opens
            
        }

		private void OnLoad(object sender, EventArgs e)
		{
			                       score = 0;




                                       //Get a new question
                                       //Display on form

                                       ts = trivia.getRandomQuestion();
                                       questionLabel.Text = ts.Question;

                                       //Random randomQuestion = new Random();
                                       //randomQuestion.Next(1, 4);

                                       int[] rndQPlacement = { 0, 1, 2, 3 };
                                       //for (int index = 0; index < rndQPlacement.Length; index++)
                                       //    rndQPlacement[index] = index;


                                       int[] shuffledNumbers = Trivia.shuffle(rndQPlacement);

                                       randomAnswer1RadioButton.Text = ts.allAnswers[shuffledNumbers[0]];
                                       randomAnswer2RadioButton.Text = ts.allAnswers[shuffledNumbers[1]];
                                       randomAnswer3RadioButton.Text = ts.allAnswers[shuffledNumbers[2]];
                                       randomAnswer4RadioButton.Text = ts.allAnswers[shuffledNumbers[3]];

                                       //randomAnswer1RadioButton.Text = ts.CorrectAnswer;
                                       //randomAnswer2RadioButton.Text = ts.FalseAnswer1;
                                       //randomAnswer3RadioButton.Text = ts.FalseAnswer2;
                                       //randomAnswer4RadioButton.Text = ts.FalseAnswer3;

            if (score == 1) correct = false;
            else correct = true;
            
		}

        private void label1_Click(object sender, EventArgs e)
        {
			
        }

		private void newQuestionButton_Click(object sender, EventArgs e)
		{
			//Get a new question
			//Display on form

			ts = trivia.getRandomQuestion();
			questionLabel.Text = ts.Question;

			//Random randomQuestion = new Random();
			//randomQuestion.Next(1, 4);

			int[] rndQPlacement = { 0, 1, 2, 3 };
			//for (int index = 0; index < rndQPlacement.Length; index++)
			//    rndQPlacement[index] = index;


			int[] shuffledNumbers = Trivia.shuffle(rndQPlacement);

			randomAnswer1RadioButton.Text = ts.allAnswers[shuffledNumbers[0]];
			randomAnswer2RadioButton.Text = ts.allAnswers[shuffledNumbers[1]];
			randomAnswer3RadioButton.Text = ts.allAnswers[shuffledNumbers[2]];
			randomAnswer4RadioButton.Text = ts.allAnswers[shuffledNumbers[3]];

			//randomAnswer1RadioButton.Text = ts.CorrectAnswer;
			//randomAnswer2RadioButton.Text = ts.FalseAnswer1;
			//randomAnswer3RadioButton.Text = ts.FalseAnswer2;
			//randomAnswer4RadioButton.Text = ts.FalseAnswer3;
		}

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void submitAnswerButton_Click(object sender, EventArgs e)
        {


            triviaSequence();
          
        }

        private void triviaSequence()
        {

              if ((randomAnswer1RadioButton.Checked && (randomAnswer1RadioButton.Text == ts.CorrectAnswer)) ||
                  (randomAnswer2RadioButton.Checked && (randomAnswer2RadioButton.Text == ts.CorrectAnswer)) ||
                  (randomAnswer3RadioButton.Checked && (randomAnswer3RadioButton.Text == ts.CorrectAnswer)) ||
                  (randomAnswer4RadioButton.Checked && (randomAnswer4RadioButton.Text == ts.CorrectAnswer)))
              {

                  MessageBox.Show("You got it right! ");
                   //ends when correct
                  score++;
              }

              else
              {
                  MessageBox.Show("You got it wrong! I'm so sorry.");
                  //end object running after one mistake
                  

              }
              ts = trivia.getRandomQuestion();
              questionLabel.Text = ts.Question;

              //Random randomQuestion = new Random();
              //randomQuestion.Next(1, 4);

              int[] rndQPlacement = { 0, 1, 2, 3 };
              //for (int index = 0; index < rndQPlacement.Length; index++)
              //    rndQPlacement[index] = index;


              int[] shuffledNumbers = Trivia.shuffle(rndQPlacement);

              randomAnswer1RadioButton.Text = ts.allAnswers[shuffledNumbers[0]];
              randomAnswer2RadioButton.Text = ts.allAnswers[shuffledNumbers[1]];
              randomAnswer3RadioButton.Text = ts.allAnswers[shuffledNumbers[2]];
              randomAnswer4RadioButton.Text = ts.allAnswers[shuffledNumbers[3]];

              numberofquestions++;
              if (numberofquestions >= 3)
              {
                  if (score == 1) correct = false;
                  else correct = true;

                  this.Close();
              }

			
        }

		private void Form1_Load(object sender, EventArgs e)
		{

		}

	
		
    }     
    
        


}

